<template>
  <div class="app-container">
    <el-dialog title="选择计划排产" :visible="open" width="1000px" append-to-body @close="close" @open="handleOpen">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="流水号" prop="serialNo">
          <el-input
            v-model="queryParams.serialNo"
            placeholder="请输入流水号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="计划号" prop="planNumber">
          <el-input
            v-model="queryParams.planNumber"
            placeholder="请输入计划号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="productionList">
        <el-table-column label="编号" align="center" prop="id"/>
        <el-table-column label="流水号" align="center" prop="serialNo"/>
        <el-table-column label="计划号" align="center" prop="planNumber"/>
        <el-table-column label="产品" align="center" prop="materialName"/>
        <el-table-column label="型号" align="center" prop="materialModel"/>
        <el-table-column label="规格" align="center" prop="materialSpecifications"/>
        <el-table-column label="单位" align="center" prop="materialUnit"/>
        <el-table-column label="BOM" align="center" prop="bomName"/>
        <el-table-column label="生产线" align="center" prop="productionLine"/>
        <el-table-column label="工艺" align="center" prop="technologyName"/>
        <el-table-column label="项目" align="center" prop="projectName"/>
        <el-table-column label="待产数量" align="center" prop="producedQuantity"/>
        <el-table-column label="已产数量" align="center" prop="quantityProduced"/>
        <el-table-column label="生产日期" align="center" prop="manufactureDate">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.manufactureDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="交货日期" align="center" prop="deliveryDate">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.deliveryDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="发布状态" align="center" prop="status">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.mes_publish_status" :value="scope.row.status"/>
          </template>
        </el-table-column>
        <el-table-column label="领料状态" align="center" prop="pickingStatus">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.mes_picking_status" :value="scope.row.pickingStatus"/>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="submitForm(scope.row)"
            >选择
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-dialog>
  </div>
</template>

<script>
import {listProduction} from "@/api/mes/production";

export default {
  name: "ProductionDilog",
  dicts: ['mes_auditor_status', 'mes_apply_status','mes_publish_status', 'mes_application_status', 'mes_picking_status'],
  props: {
    open: {
      type: Boolean,
      default: false
    },
    pickingStatus: {
      type: String,
      default: null
    }

  },

  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 计划排产表格数据
      productionList: [],
      // 弹出层标题
      title: "",

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        serialNo: null,
        planNumber: null,
        pickingStatus: this.pickingStatus,
        status: 1
      }
    };
  },
  methods: {
    handleOpen() {
      this.getList();
    },
    /** 查询计划排产列表 */
    getList() {
      this.loading = true;
      listProduction(this.queryParams).then(response => {
        this.productionList = response.rows
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    close() {
      this.$emit("close");
    },
    /** 提交按钮 */
    submitForm(row) {
      this.$emit('fun', row);
      this.close()
    },
  },
};
</script>
